/*
 * DiGraph.h
 *
 *  Created on: 22/06/2013
 *      Author: marcio
 */

#ifndef DIGRAPH_H_
#define DIGRAPH_H_

class DiGraph {
	long n;

	bool** edges;

public:
	DiGraph(long n);

	virtual ~DiGraph();

	void addEdge(long i, long j);

	void removeEdge(long i, long j);

	long degreeIn(long i);

	long degreeOut(long i);

	bool hasEdge(long i, long j);
};

DiGraph::DiGraph(long n){
	this->n = n;
	edges = new bool*[n];
	for(long i = 0; i < n; i++) edges[i] = new bool[n];
}

virtual DiGraph::~DiGraph(){
	for(long i = 0; i < n; i++) delete edges[i];
	delete edges;
}

inline void DiGraph::addEdge(long i, long j){
	edges[i][j] = true;
}

inline void DiGraph::removeEdge(long i, long j){
	edges[i][j] = false;
}

inline long DiGraph::degreeIn(long i){
	long deg = 0;
	for(long j = 0; j < i; j++)
		if(edges[i][j])deg++;
	return deg;
}

inline long DiGraph::degreeOut(long i){
	long deg = 0;
	for(long j = i+1; j < n; j++)
		if(edges[i][j])deg++;
	return deg;
}

inline bool DiGraph::hasEdge(long i, long j){
	return edges[i][j];
}


#endif /* DIGRAPH_H_ */
